/**
 *  Copyright (C) 2013  Piotr Szczepa�ski
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package edu.pw.elka.gtsna.graph;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.Vector;

import edu.pw.elka.gtsna.graph_creator.GraphCreator;

/**
 * @author Piotr Lech Szczepa�ski
 * @author P.Szczepanski@ii.pw.edu.pl 
 *
 */
public class UndirectedGraph extends Graph {

	public UndirectedGraph(int numOfNodes){
		super(numOfNodes);
	}
	
	public UndirectedGraph(GraphCreator creator){	
		super(creator.getNumOfNodes());
		for(Edge e: creator){
			addEdge(e);
		}
	}
	
	public UndirectedGraph(Graph gr){
		super(gr);
	}
	
	/**
	 * 
	 * @param subgraph - the set of vertices
	 * @return the set of vertices incident to all vertices from subgraph. 
	 * 		   NOTE: The vertices from the set subgraph are excluded from return
	 */
	public Set<Integer> getNeigbours(Set<Integer> subgraph){
		Set<Integer> neigbours = new LinkedHashSet<Integer>();
		for(int i : subgraph) {
			for (int u: getNeigbours(i)){
				if (!subgraph.contains(u)) {
					neigbours.add(u);
				}
			}
		}
		return neigbours;
	}
	
	@Override
	public void addEdge(int u, int v){
		super.addEdge(u, v);
		graphNeighbours[pos(v)].add(u);
	}

	public void removeEdge(int u, int v){
		super.removeEdge(u, v);
		graphNeighbours[pos(v)].remove(u);
	}

	/* (non-Javadoc)
	 * @see edu.pw.elka.gtsna.graph.Graph#clone()
	 */
	@Override
	public Graph clone() throws CloneNotSupportedException
	{
		Graph clonedObj = null;

		clonedObj= new UndirectedGraph(this);
		return clonedObj;
	}




	
}
